package com.superms.platform.filter;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Component;

import com.jeesuite.springweb.WebConstants;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.superms.base.model.LoginUserInfo;

@Component
public class AuthFilter extends ZuulFilter {

	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public Object run() {
		RequestContext ctx = RequestContext.getCurrentContext();
		LoginUserInfo user= (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
		if(user != null){
			ctx.addZuulRequestHeader(WebConstants.HEADER_AUTH_USER, user.toEncodeString());
		}
		return null;
	}

	@Override
	public String filterType() {
		return "pre";
	}

	@Override
	public int filterOrder() {
		return 1;
	}

}
